<template>
    <div class="main">
        <aside-com></aside-com>

        <div class="main-container scroll">
            <header-com></header-com>

            <div class="main-container-cover">
                <div class="main-breadcrumb">
                    <!-- 面包屑 -->
                    <el-breadcrumb separator="/" class="main-breadcrumb-cover">
                        <el-breadcrumb-item v-for="(item, index) in breadcrumbList" :to="{ name: item.name }" :key="index">
                            {{ item.meta.name }}
                        </el-breadcrumb-item>
                    </el-breadcrumb>
                    <!-- 页面标题 -->
                    <p>{{ title }}</p>
                </div>

                <router-view></router-view>
            </div>

        </div>
    </div>
</template>

<script type="text/javascript">
    import AsideCom from '@/components/main/aside.component'
    import HeaderCom from '@/components/main/header.component'

    export default {
        name: "mainView",
        data() {
            return {
                breadcrumbList: [],
                title: '',
                isCollapse: false
            }
        },
        components: {
            AsideCom,
            HeaderCom
        },
        watch: {
            $route (data) {
                this.processBread(data);
            }
        },
        methods: {
            /**
             * 处理全局面包屑
             * @param route 当前路由信息
             */
            processBread (route) {
                this.breadcrumbList = route.matched.filter(el => {
                    return el.name;
                });

                this.title = route.meta.name || '';
            },

            resize () {
                let the = this;

                if(window.innerWidth < 1280) {
                    the.$eventBus.emit('updateCollapse', {
                        status: true
                    });
                } else {
                    the.$eventBus.emit('updateCollapse', {
                        status: false
                    });
                }
            }
        },
        mounted() {
            let the = this;
            this.processBread(this.$route);

            // TODO: 更新title
            // 更新 title
            this.$eventBus.on('updateTitle', (title) => {
                this.title = title;
            });
            the.resize();
            window.onresize = function () {
                the.resize();
            }
        }
    }
</script>

<style rel="stylesheet/scss" lang="scss">
    .main {
        height: 100vh;
        display: flex;
        background: #eee;

        &-breadcrumb {
            padding: 16px 32px;
            background: #fff;

            &-cover {
                @include pxAndLh(14);
            }

            p {
                @include pxAndLh(20);
                padding-top: 16px;
                color: $text-color-black-85;
            }
        }

        &-container {
            flex: 1;
            overflow: auto;

            &-cover {
                min-height: calc(100% - 76px - 64px);
                display: flex;
                flex-direction: column;
            }
        }

        .footer {
            height: 76px;
            line-height: 76px;
            text-align: center;
            font-size: 12px;
            color: $text-color-black-45;
        }
    }
</style>
